package com.xinfu.newproject.ui.carFee;


import android.os.Bundle;
import android.view.View;
import android.widget.TextView;

import androidx.recyclerview.widget.LinearLayoutManager;
import androidx.recyclerview.widget.RecyclerView;

import com.google.gson.Gson;
import com.xinfu.newproject.R;
import com.xinfu.newproject.activity.ParkingActivity;
import com.xinfu.newproject.adapter.park_adapter.MonthCardAdapter;
import com.xinfu.newproject.base.BaseFragment;
import com.xinfu.newproject.bean.login.LoginBean;
import com.xinfu.newproject.bean.park_bean.bean.AddMonthCarBean;
import com.xinfu.newproject.bean.park_bean.bean.CheckMonthParkBean;
import com.xinfu.newproject.bean.park_bean.bean.FeeListBean;
import com.xinfu.newproject.bean.park_bean.bean.GetMonthCarListBean;
import com.xinfu.newproject.bean.park_bean.bean.GetParkingBean;
import com.xinfu.newproject.bean.park_bean.bean.PaymentsBean;
import com.xinfu.newproject.bean.paycost.bean.ComputeParkingBean;
import com.xinfu.newproject.ui.carFee.add_parking.AddTemporaryParkFragment;
import com.xinfu.newproject.interface_.SwichFragmentInterface;
import com.xinfu.newproject.presenter.ParkingPresenter;
import com.xinfu.newproject.util.BToast;
import com.xinfu.newproject.util.SPUtils;
import com.xinfu.newproject.view.IView;

import butterknife.BindView;
import butterknife.OnClick;
import io.reactivex.disposables.Disposable;

import static com.xinfu.newproject.contants.Constant.LOGIN;


/**
 * 月卡
 */
public class MonthCardFragment extends BaseFragment implements IView.IParkingView {

    @BindView(R.id.layout_next_step_tv)
    TextView nextStepTv;

    @BindView(R.id.fragment_month_card_rv)
    RecyclerView mRecyclerView;

    private MonthCardAdapter monthCardAdapter;

    private SwichFragmentInterface swichFragmentInterface;

    private ParkingPresenter parkingPresenter = new ParkingPresenter(this);

    public MonthCardFragment() {
        // Required empty public constructor
    }

    public static MonthCardFragment getInstance(String carTypeParam) {
        MonthCardFragment fragment = new MonthCardFragment();
        Bundle bundle = new Bundle();
        bundle.putString("carType", carTypeParam);
        fragment.setArguments(bundle);
        return fragment;
    }


    @Override
    protected int setLayoutResourceID() {
        return R.layout.fragment_month_card;
    }

    @Override
    protected void setUpView() {
        nextStepTv.setText("添加月卡车");
        mRecyclerView.setLayoutManager(new LinearLayoutManager(getMContext()));
        monthCardAdapter = new MonthCardAdapter();
        mRecyclerView.setAdapter(monthCardAdapter);
    }

    @Override
    protected void setUpData() {

    }

    @Override
    public void onResume() {
        super.onResume();
        if (isLogin()) {
            parkingPresenter.getMonthCarList();
        }
    }

    @OnClick({R.id.layout_next_step_tv})
    public void onClick(View view) {
        switch (view.getId()) {
            case R.id.layout_next_step_tv:
                Bundle bundle = new Bundle();
                bundle.putInt("type", 1);
                ((ParkingActivity) getMContext()).startIntentActivity(AddTemporaryParkFragment.class, bundle);
                break;
        }
    }

    /**
     * 判断是否可以请求数据
     */
    String token, userId, userName;
    int urlType;

    private boolean isLogin() {

        LoginBean.ResultBean resultBean;
        String responseIntent = (String) SPUtils.get(getMContext(), LOGIN, "0");
        if (!responseIntent.equals("0")) {
            resultBean = new Gson().fromJson(responseIntent, LoginBean.ResultBean.class);
            token = resultBean.getToken();
            userId = resultBean.getUserInfo().getId();
            userName = resultBean.getUserInfo().getUsername();
        } else {
            BToast.showText(getMContext(), "请先登录");
            return false;
        }

        return true;
    }

    @Override
    public String header() {
        return "1";
    }

    @Override
    public String userId() {
        return userId;
    }

    @Override
    public String parkInfoId() {
        return null;
    }

    @Override
    public String carId() {
        return null;
    }

    @Override
    public Integer carType() {
        return 1;
    }

    @Override
    public String projectId() {
        return null;
    }

    @Override
    public String exclusiveFlag() {
        return null;
    }

    @Override
    public String monthCarType() {
        return null;
    }

    @Override
    public String roomId() {
        return null;
    }

    @Override
    public String owner() {
        return null;
    }

    @Override
    public String mobile() {
        return null;
    }

    @Override
    public String images() {
        return null;
    }

    @Override
    public String remark() {
        return null;
    }

    @Override
    public Integer idType() {
        return null;
    }

    @Override
    public String filed1() {
        return null;
    }

    @Override
    public String id() {
        return null;
    }

    @Override
    public String startTime() {
        return null;
    }

    @Override
    public String orderId() {
        return null;
    }

    @Override
    public String licensePlate() {
        return null;
    }

    @Override
    public void showToast(String content) {
        BToast.showText(getMContext(), content);
    }

    @Override
    public void closeDispose(Disposable disposable) {

    }

    @Override
    public void showProgress() {

    }

    @Override
    public void hideProgress() {

    }

    @Override
    public void getMsg(GetParkingBean getParkingBean) {

    }

    @Override
    public void getMsg(CheckMonthParkBean checkMonthParkBean) {

    }

    @Override
    public void getMsg(AddMonthCarBean addMonthCarBean) {

    }

    @Override
    public void getMsg(GetMonthCarListBean getMonthCarListBean) {
        if (getMonthCarListBean.getResult() != null && getMonthCarListBean.getResult().size() > 0) {
            monthCardAdapter.setNewData(getMonthCarListBean.getResult());
        }
    }

    @Override
    public void getMsg(PaymentsBean paymentsBean) {

    }

    @Override
    public void getMsg(ComputeParkingBean computeParkingBean) {

    }

    @Override
    public void getMsg(FeeListBean feeListBean) {

    }
}
